/*
 *  Copyright 2012 yura.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package org.opu.odg.dg.incomingdata;

import java.io.Serializable;
import java.util.Properties;
import org.simpleframework.xml.ElementMap;
import org.simpleframework.xml.Root;

/**
 *
 * @author yura
 */
@Root(name="variables")
public class GlobalVariables implements Cloneable, Serializable{

    @ElementMap(keyType=String.class, valueType=String.class, attribute=true, entry="variable", inline=true, data=true)
    private Properties properties;

    private GlobalVariables() {
        // for simple framework
    }

    public GlobalVariables(Properties properties) {
        this.properties = properties;
    }

    public String get(String name) {
        return properties.getProperty(name, "");
    }

    public boolean contain(String name) {
        return properties.contains(name);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final GlobalVariables other = (GlobalVariables) obj;
        if (this.properties != other.properties && (this.properties == null || !this.properties.equals(other.properties))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 67 * hash + (this.properties != null ? this.properties.hashCode() : 0);
        return hash;
    }

    @Override
    protected GlobalVariables clone() throws CloneNotSupportedException {
        Properties prop = new Properties();
        prop.putAll(properties);
        return new GlobalVariables(prop);
    }

    @Override
    public String toString() {
        return "GlobalVariables{" + properties + '}';
    }

}
